<?php include_once('header.php'); ?>
	<?PHP
		function check_lang() { 
		if(isSet($_GET['lang']))
		{
			$lang = $_GET['lang'];
			
			// register the session and set the cookie
			$_SESSION['lang'] = $lang;
			
		}
		else if(isSet($_SESSION['lang']))
		{
			$lang = $_SESSION['lang'];
		}
		else if(isSet($_COOKIE['lang']))
		{
			$lang = $_COOKIE['lang'];
		}
		else
		{
			$lang = 'en';
		}
		
		//directory name 
		  $dir = 'languages'; 
		
		//no we return the langauge wanted ! 
		//Returned String Format: dirname/filename.ext 
		  return "$dir/$lang.lng"; 
	} 
	?>
	<?PHP
	//this function will check user language and return the file name to be included .. 
	$lang = check_lang();
	$_SESSION['abc'] = 'timkiem';
	include($lang); 
	?>
	<div id="wrapper1">
		<!-- Header : ---------------------  Start -------------------------
			Describle : banner + logo + search + link (english, vietnam, rss)-->	
		<div id="header" class="container" align="center">
			<!-- text link -->
			<div style="float:left; margin:40px 30px auto; font-size:18px; color:#666666">
				<b> Site map | 
				<a onclick="developfunction('')" id="english" 
					onmouseover="change_color_link('english', '#000000')" 
					onmouseout="change_color_link('english', '#666666')"
					href="searchform.php?lang=en" > 
						English </a> | 
				<a onclick="refreshView()" id="vietnam" 
					onmouseover="change_color_link('vietnam', '#000000')" 
					onmouseout="change_color_link('vietnam', '#666666')"
					href="searchform.php?lang=vn"> 
						Vietnam </a> | 
				<a id="rss" onclick="developfunction('')"
					onmouseover="change_color_link('rss', '#000000')" 
					onmouseout="change_color_link('rss', '#666666')"
					> 
						RSS </a></b>			</div>
			
<?php include_once('menu.php'); ?>
	<!-- topic -->
    <div id="hidden" style="width:950px;height:480px; margin: 10px 10px 10px 10px; position:absolute;">
        <div id="sublayoutthumbnail">
            <img id="hiddenimage" src="images/emptyimage.png" width="100%" height="100%" alt="no image" name="no image" title="no image"/>
        </div>
        <div id="sublayouttext" style="width:760px;height:460px; margin: 10px 10px 10px 10px; overflow:auto;">
        </div>
    </div>
	<?php 
        $link = connectDB();
        $tbl_name='topic'; // Table name
		$searchstring=$_POST['searchtext'];
        
        $sql="SELECT * FROM topic WHERE titletext LIKE ('%$searchstring%') OR subdescrible LIKE ('%$searchstring%') OR content LIKE ('%$searchstring%')";
        $result=mysql_query($sql,$link);
        
        // Mysql_num_row is counting table row
        $count=mysql_num_rows($result);
        if($count == 0) {
            echo "<p>không có bài viết nào.</p>";
        }else {
        $count1 = 0;
        $margintop123;
        while ($row = mysql_fetch_assoc($result)) {
            $buttonid='topic'.$count1;
            $view='maincontentsublayout'.$count1;
            $contenthtml = (string)$row["content"];
            echo  '<div class="maincontentsublayout" id="'.$view.'">
                <div id="sublayoutthumbnail">
                <img src="'.$row["titleimage"].'" width="100%" height="100%" onclick="removeView(\''.$view.'\', \''.$contenthtml.'\')"/>
                </div>
                <div id="sublayouttext">
                    <p style="font-weight:bold; font-size:16px;">'.$row["titletext"].' </p>
                    <p>'.$row["subdescrible"].'</p>
                </div>
                <div id="buttonreadmore">
                    <img src="images/readmorebutton.png" id="'.$buttonid.'" width="100%" height="100%"  
                        onclick="removeView(\''.$view.'\',\''.$contenthtml.'\')"
                        onmouseover="change_image_button(\''.$buttonid.'\', \'images/readmorebuttonover.png\')"
                        onmouseout="change_image_button(\''.$buttonid.'\', \'images/readmorebutton.png\')"/>
                </div>
            </div>';
            if($count1%2==0) {
                $margintop=(200*$count1/2)+10;
                $margintop123=$margintop+250;
                $id=$count1;
                echo '<div class="postraitspacecontent" id="postraitspacecontent'.$id.'" style="margin-left: 455px; margin-top: '.$margintop.'px;"></div>';
            }
            $count1=$count1+1;
        }
        echo '<div id="landscapespacecontent" style="margin-top: '.$margintop123.'px;"></div>';
        }
        mysql_free_result($result);
    ?>
<?php include_once('footer.php'); ?>